//==============================================================================
//	File:		$RCSfile: Crossbar.rdl,v $
//	Version:	$Revision: 1.5 $
//	Desc:		Crossbar Parameter & Array RDL Example
//	Author:		Greg Gibeling
//	Copyright:	Copyright 2005-2007 UC Berkeley
//
//	This copyright header must appear in all derivative works
//==============================================================================

//==============================================================================
//	Section:	License
//==============================================================================
// Copyright (c) 2005-2007, Regents of the University of California
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//     - Redistributions of source code must retain the above copyright notice,
//         this list of conditions and the following disclaimer. 
//     - Redistributions in binary form must reproduce the above copyright
//         notice, this list of conditions and the following disclaimer
//         in the documentation and/or other materials provided with the
//         distribution. 
//     - Neither the name of the University of California, Berkeley nor the
//         names of its contributors may be used to endorse or promote
//         products derived from this software without specific prior
//         written permission. 
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//==============================================================================

//==============================================================================
//	Section:	CVS Change Log
//==============================================================================
//	$Log: Crossbar.rdl,v $
//	Revision 1.5  2007/03/24 19:45:47  sshd_server
//	Added better description of index# and arrays
//	
//	Revision 1.4  2007/03/05 23:37:43  sshd_server
//	Fixed formatting (typos)
//	
//	Revision 1.3  2007/02/28 20:47:15  sshd_server
//	Spelling and typo corrections
//	
//	Revision 1.2  2007/02/27 02:10:59  sshd_server
//	Created RDL examples from RDLC2 test cases, FLEET and Overlog applications
//	
//==============================================================================

//------------------------------------------------------------------------------
//	Unit:		Element
//	Desc:		This unit represents a single element of the crossbar example.
//				It has a simple pair of parameters for the number of ports, and
//				the bitwidth of each port. 
//------------------------------------------------------------------------------
unit <NPorts, Width> {
	// An array of ports (as opposed to a port which has an array of
	// messages as it's type) with an unspecified width.  The width will be
	// inferred from whatever these ports are connected to.
	input bit<>[$NPorts] In;
		
	// An array of ports with an unspecified bound.  The bound of the
	// array will be inferred from whatever these ports are connected to.
	output bit<$Width>[] Out;
} Element;
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//	Unit:		CrossbarExample
//	Desc:		This unit instantiates an array of "Element" units, and connects
//				their inputs and outputs in a full crossbar configuration.  The
//				real power of this example is in the fact that the size of the
//				various arrays and bitwidths are all inferred from two simple
//				constants shown below.
//				The point of this example is to show off the "index#?" syntax
//				for connecting an array of channels to an array of ports on an
//				array of instances, in conjunction with the ability to leave
//				array bounds unspecified (all the places with "[]" and "<>").
//				In combination these constructs allow a wide variety to
//				structures be specified with a minimum of effort and duplicated
//				text.
//				Note that because RDLC2 does not support expressions
//				(computations) with parameters, many structures are still not
//				possible, e.g. a compact description of a ring network.
//------------------------------------------------------------------------------
unit {
	// A single dimension array of elements.  In addition, this line contains
	// the actual crossbar connections as a combination of positional port
	// connections with indices.  The fact that the connections to the "In" and
	// "Out" port arrays have their indices reversed is what creates a crossbar.
	instance Element<2, 8>	Elements[]([index#0][index#1](Channels[index#1][index#0]), [index#0][index#1](Channels[index#0][index#1]));
	
	// A little explanation of array connections follows...
	// The string "[index#0][index#1](Channels[index#1][index#0])" is connecting
	// a 1 dimensional array of ports ("In") on the 1 dimensional array of
	// instances ("Elements") to the 2 dimensional array of channels ("Channel").
	// This is similar to a pair of nested for loops, iterating over the arrays
	// "Elements" and "In", where at each iteration this statement connects the
	// port "Elements[index#0].In[index#1]" to "Channels[index#1][index#0]".
	
	// In essence, (if all array bounds are 2), this is connecting:
	// Elements[0].In[0] to Channels[0][0]
	// Elements[0].In[1] to Channels[1][0]
	// Elements[1].In[0] to Channels[0][1]
	// Elements[1].In[1] to Channels[1][1]
	// Please see "doc-files/Crossbar.svg" for a graphical version of this.
	
	// In RDL the "index#" is a keyword, followed by a number denoting an
	// unbound loop variables.
	// Finally, in the above "Elements" declaration there are two sets of
	// variables, one, as described above, for the "In" port array, and an
	// entirely separate set for the "Out" array, which is similar.  The two
	// are separated by the comma.
	
	// Two dimensional array of channels.
	channel					Channels[][];
} CrossbarExample;
//------------------------------------------------------------------------------